package endpoints

import (
	"context"

	"github.com/go-kit/kit/endpoint"

	"gokit_study/services"
)

type UserRequest struct {
	UserId string `json:"user_id"`
}

type UserResponse struct {
	UserName string `json:"user_name"`
}

func GenerateUserEndpoint(userService services.UserServiceInterface) endpoint.Endpoint {
	return func(ctx context.Context, request interface{}) (response interface{}, err error) {
		req := request.(UserRequest)
		userName, err := userService.GetName(req.UserId)
		if err != nil {
			return UserResponse{UserName: userName}, nil
		}
		return UserResponse{UserName: userName}, err
	}
}
